<!DOCTYPE html>
<html lang="en">

<!-- Head tag -->
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!--Description-->
    
        <meta name="description" content="123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798">
    

    <!--Author-->
    
        <meta name="author" content="John Doe">
    

    <!--Open Graph Title-->
    
        <meta property="og:title" content="Vue父子传值，路由，watch"/>
    

    <!--Open Graph Description-->
    

    <!--Open Graph Site Name-->
    <meta property="og:site_name" content="Hexo"/>

    <!--Type page-->
    
        <meta property="og:type" content="article" />
    

    <!--Page Cover-->
    

        <meta name="twitter:card" content="summary" />
    

    <!-- Title -->
    
    <title>Vue父子传值，路由，watch - Hexo</title>

    <!-- Bootstrap Core CSS -->
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>

    <!-- Custom CSS -->
    <link rel="stylesheet" href="/css/style.css">

    <!-- Custom Fonts -->
    <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="//fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic" rel="stylesheet" type="text/css">
    <link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="//oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="//oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- Gallery -->
    <link href="//cdnjs.cloudflare.com/ajax/libs/featherlight/1.3.5/featherlight.min.css" type="text/css" rel="stylesheet" />

    <!-- Google Analytics -->
    


    <!-- favicon -->
    
	
</head>


<body>

    <!-- Menu -->
    <!-- Navigation -->
<nav class="navbar navbar-default navbar-custom navbar-fixed-top">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header page-scroll">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/">逐风</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav navbar-right">
                
                    <li>
                        <a href="/">
                            
                                Home
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/archives">
                            
                                Archives
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/tags">
                            
                                Tags
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/categories">
                            
                                Categories
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="https://github.com/klugjo/hexo-theme-clean-blog">
                            
                                <i class="fa fa-github fa-stack-2x"></i>
                            
                        </a>
                    </li>
                
            </ul>
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
</nav>

    <!-- Main Content -->
    <!-- Page Header -->
<!-- Set your background image for this header in your post front-matter: cover -->

<header class="intro-header" style="background-image: url('http://www.codeblocq.com/assets/projects/hexo-theme-clean-blog/img/home-bg.jpg')">
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <div class="post-heading">
                    <h1>Vue父子传值，路由，watch</h1>
                    
                    <span class="meta">
                        <!-- Date and Author -->
                        
                        
                            2017-10-24
                        
                    </span>
                </div>
            </div>
        </div>
    </div>
</header>

<!-- Post Content -->
<article>
    <div class="container">
        <div class="row">

            <!-- Tags and categories -->
           

            <!-- Gallery -->
            

            <!-- Post Main Content -->
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div></pre></td><td class="code"><pre><div class="line">父组件向子组件传值</div><div class="line">父组件传data中的值，子组件使用(只有读取权限，修改会报错)</div><div class="line"></div><div class="line">在html的子组件中 v-bind:**=&quot;父组件的值&quot;</div><div class="line">在子组件的定义中props:[&apos;**&apos;]</div><div class="line"></div><div class="line">父组件向子组件传方法，	</div><div class="line">在html的子组件中 v-on:**=&quot;父组件的方法&quot;</div><div class="line">在子组件的定义中this.$emit(&apos;func&apos;,子组件向父组件传值)</div><div class="line"></div><div class="line"></div><div class="line">Vue中的DOM操作</div><div class="line">ref指令</div><div class="line">ref=&quot;**&quot;</div><div class="line">this.$refs.**.innerHtml/.方法</div><div class="line"></div><div class="line">路由的使用 vue-router.js</div><div class="line">vue-router 提供的元素，专门用来 当作占位符的，将来，路由规则，匹配到的组件，就会展示到这个 router-view 中去 </div><div class="line">    &lt;router-view&gt;&lt;/router-view&gt;</div><div class="line"></div><div class="line"> &lt;!-- router-link 默认渲染为一个a 标签 --&gt;</div><div class="line">    &lt;router-link to=&quot;/login&quot; tag=&quot;span&quot;&gt;登录&lt;/router-link&gt;</div><div class="line">.router-link-active默认激活的类样式</div><div class="line">new VueRouter(&#123; </div><div class="line">routes: [</div><div class="line"> &#123; path: &apos;/&apos;, redirect:   &apos;/login&apos; &#125;,   //redirect 重定向</div><div class="line">  &#123; path: &apos;/login&apos;, component: login &#125;   </div><div class="line">	</div><div class="line">	// 定义组件的模板对象</div><div class="line">    var login = &#123;</div><div class="line">      template: &apos;&lt;h1&gt;登录组件&lt;/h1&gt;&apos;</div><div class="line">    &#125;</div><div class="line">]</div><div class="line"> &#125;)</div><div class="line"></div><div class="line">路由传参</div><div class="line"> 1. &lt;router-link to=&quot;/login?id=10&amp;name=zs&quot;&gt;登录&lt;/router-link&gt;</div><div class="line"> 通过$route.query.**获取</div><div class="line">2.  &lt;router-link to=&quot;/login/12/ls&quot;&gt;登录&lt;/router-link&gt;</div><div class="line">        &#123; path: &apos;/login/:id/:name&apos;, component: login &#125;,</div><div class="line">路由嵌套</div><div class="line">在上级路由的模板template里放子路由	</div><div class="line">//上级路由	</div><div class="line">    &lt;router-link to=&quot;/account&quot;&gt;Account&lt;/router-link&gt;</div><div class="line"> &lt;template id=&quot;tmpl&quot;&gt;</div><div class="line">    &lt;div&gt;</div><div class="line">      &lt;h1&gt;这是 Account 组件&lt;/h1&gt;</div><div class="line"></div><div class="line">      &lt;router-link to=&quot;/account/login&quot;&gt;登录&lt;/router-link&gt;</div><div class="line">      &lt;router-link to=&quot;/account/register&quot;&gt;注册&lt;/router-link&gt;</div><div class="line"></div><div class="line">      &lt;router-view&gt;&lt;/router-view&gt;</div><div class="line">    &lt;/div&gt;</div><div class="line">  &lt;/template&gt;</div><div class="line"> routes: [</div><div class="line">        &#123;</div><div class="line">          path: &apos;/account&apos;,</div><div class="line">          component: account,</div><div class="line">          // 使用 children 属性，实现子路由</div><div class="line">          children: [</div><div class="line">            &#123; path: &apos;login&apos;, component: login &#125;,</div><div class="line">            &#123; path: &apos;register&apos;, component: register &#125;</div><div class="line">          ]</div><div class="line">        &#125;  </div><div class="line">	</div><div class="line">//多view布局</div><div class="line">&lt;router-view&gt;&lt;/router-view&gt;</div><div class="line">      &lt;router-view name=&quot;left&quot;&gt;&lt;/router-view&gt;</div><div class="line">      &lt;router-view name=&quot;main&quot;&gt;&lt;/router-view&gt;</div><div class="line">	</div><div class="line">	 path: &apos;/&apos;, components: &#123;</div><div class="line">            //default  默认放的，可以不加&apos;&apos;</div><div class="line">            &apos;default&apos;: header,</div><div class="line">            &apos;left&apos;: leftBox,</div><div class="line">            &apos;main&apos;: mainBox</div><div class="line">          &#125;</div><div class="line">watch 监控data中指定的数据的变化</div><div class="line">watch:&#123;&apos;**&apos;/**可以不加&apos;&apos;,function(newVal,oldVal)&#123;&#125; &#125;</div><div class="line">也可以监测路由地址的变化</div><div class="line"> &apos;$route.path&apos;:function(newVal)&#123;&#125;</div><div class="line"></div><div class="line">computed 计算属性  在引用的时候，不要加 ()去调用，把它当作普通属性使用；</div><div class="line">计算属性的求值结果，会被缓存起来，方便下次直接使用,效率高些</div><div class="line">把结果return 出去</div></pre></td></tr></table></figure>

                
            </div>

            <!-- Comments -->
            
                <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                    


                </div>
            
        </div>
    </div>
</article>

    <!-- Footer -->
    <hr />

<!-- Footer -->
<footer>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <ul class="list-inline text-center">
                    

                    

                    
                        <li>
                            <a href="https://github.com/klugjo/hexo-theme-clean-blog" target="_blank">
                                <span class="fa-stack fa-lg">
                                    <i class="fa fa-circle fa-stack-2x"></i>
                                    <i class="fa fa-github fa-stack-1x fa-inverse"></i>
                                </span>
                            </a>
                        </li>
                    

                    

                    

                    
                </ul>
                <p class="copyright text-muted">&copy; 2018 John Doe<br></p>
                <p class="copyright text-muted">Original Theme <a target="_blank" href="http://startbootstrap.com/template-overviews/clean-blog/">Clean Blog</a> from <a href="http://startbootstrap.com/" target="_blank">Start Bootstrap</a></p>
                <p class="copyright text-muted">Adapted for <a target="_blank" href="https://hexo.io/">Hexo</a> by <a href="http://www.codeblocq.com/" target="_blank">Jonathan Klughertz</a></p>
            </div>
        </div>
    </div>
</footer>


    <!-- After footer scripts -->
    
<!-- jQuery -->
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>

<!-- Bootstrap -->
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<!-- Gallery -->
<script src="//cdnjs.cloudflare.com/ajax/libs/featherlight/1.3.5/featherlight.min.js" type="text/javascript" charset="utf-8"></script>

<!-- Disqus Comments -->



</body>

</html>